{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Requirement already satisfied: tensorflow in c:\\users\\fer_u\\pycharmprojects\\cyberattacksattention\\venv\\lib\\site-packages (2.11.0)"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "WARNING: You are using pip version 21.3.1; however, version 22.3.1 is available.\n",
      "You should consider upgrading via the 'C:\\Users\\Fer_U\\PycharmProjects\\CyberattacksAttention\\venv\\Scripts\\python.exe -m pip install --upgrade pip' command.\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Requirement already satisfied: tensorflow-intel==2.11.0 in c:\\users\\fer_u\\pycharmprojects\\cyberattacksattention\\venv\\lib\\site-packages (from tensorflow) (2.11.0)\n",
      "Requirement already satisfied: wrapt>=1.11.0 in c:\\users\\fer_u\\pycharmprojects\\cyberattacksattention\\venv\\lib\\site-packages (from tensorflow-intel==2.11.0->tensorflow) (1.14.1)\n",
      "Requirement already satisfied: h5py>=2.9.0 in c:\\users\\fer_u\\pycharmprojects\\cyberattacksattention\\venv\\lib\\site-packages (from tensorflow-intel==2.11.0->tensorflow) (3.7.0)\n",
      "Requirement already satisfied: setuptools in c:\\users\\fer_u\\pycharmprojects\\cyberattacksattention\\venv\\lib\\site-packages (from tensorflow-intel==2.11.0->tensorflow) (60.2.0)\n",
      "Requirement already satisfied: absl-py>=1.0.0 in c:\\users\\fer_u\\pycharmprojects\\cyberattacksattention\\venv\\lib\\site-packages (from tensorflow-intel==2.11.0->tensorflow) (1.3.0)\n",
      "Requirement already satisfied: grpcio<2.0,>=1.24.3 in c:\\users\\fer_u\\pycharmprojects\\cyberattacksattention\\venv\\lib\\site-packages (from tensorflow-intel==2.11.0->tensorflow) (1.51.1)\n",
      "Requirement already satisfied: opt-einsum>=2.3.2 in c:\\users\\fer_u\\pycharmprojects\\cyberattacksattention\\venv\\lib\\site-packages (from tensorflow-intel==2.11.0->tensorflow) (3.3.0)\n",
      "Requirement already satisfied: astunparse>=1.6.0 in c:\\users\\fer_u\\pycharmprojects\\cyberattacksattention\\venv\\lib\\site-packages (from tensorflow-intel==2.11.0->tensorflow) (1.6.3)\n",
      "Requirement already satisfied: gast<=0.4.0,>=0.2.1 in c:\\users\\fer_u\\pycharmprojects\\cyberattacksattention\\venv\\lib\\site-packages (from tensorflow-intel==2.11.0->tensorflow) (0.4.0)\n",
      "Requirement already satisfied: packaging in c:\\users\\fer_u\\pycharmprojects\\cyberattacksattention\\venv\\lib\\site-packages (from tensorflow-intel==2.11.0->tensorflow) (22.0)\n",
      "Requirement already satisfied: typing-extensions>=3.6.6 in c:\\users\\fer_u\\pycharmprojects\\cyberattacksattention\\venv\\lib\\site-packages (from tensorflow-intel==2.11.0->tensorflow) (4.4.0)\n",
      "Requirement already satisfied: libclang>=13.0.0 in c:\\users\\fer_u\\pycharmprojects\\cyberattacksattention\\venv\\lib\\site-packages (from tensorflow-intel==2.11.0->tensorflow) (14.0.6)\n",
      "Requirement already satisfied: six>=1.12.0 in c:\\users\\fer_u\\pycharmprojects\\cyberattacksattention\\venv\\lib\\site-packages (from tensorflow-intel==2.11.0->tensorflow) (1.16.0)\n",
      "Requirement already satisfied: termcolor>=1.1.0 in c:\\users\\fer_u\\pycharmprojects\\cyberattacksattention\\venv\\lib\\site-packages (from tensorflow-intel==2.11.0->tensorflow) (2.1.1)\n",
      "Requirement already satisfied: google-pasta>=0.1.1 in c:\\users\\fer_u\\pycharmprojects\\cyberattacksattention\\venv\\lib\\site-packages (from tensorflow-intel==2.11.0->tensorflow) (0.2.0)\n",
      "Requirement already satisfied: numpy>=1.20 in c:\\users\\fer_u\\pycharmprojects\\cyberattacksattention\\venv\\lib\\site-packages (from tensorflow-intel==2.11.0->tensorflow) (1.23.5)\n",
      "Requirement already satisfied: tensorflow-io-gcs-filesystem>=0.23.1 in c:\\users\\fer_u\\pycharmprojects\\cyberattacksattention\\venv\\lib\\site-packages (from tensorflow-intel==2.11.0->tensorflow) (0.28.0)\n",
      "Requirement already satisfied: tensorflow-estimator<2.12,>=2.11.0 in c:\\users\\fer_u\\pycharmprojects\\cyberattacksattention\\venv\\lib\\site-packages (from tensorflow-intel==2.11.0->tensorflow) (2.11.0)\n",
      "Requirement already satisfied: keras<2.12,>=2.11.0 in c:\\users\\fer_u\\pycharmprojects\\cyberattacksattention\\venv\\lib\\site-packages (from tensorflow-intel==2.11.0->tensorflow) (2.11.0)\n",
      "Requirement already satisfied: protobuf<3.20,>=3.9.2 in c:\\users\\fer_u\\pycharmprojects\\cyberattacksattention\\venv\\lib\\site-packages (from tensorflow-intel==2.11.0->tensorflow) (3.19.6)\n",
      "Requirement already satisfied: tensorboard<2.12,>=2.11 in c:\\users\\fer_u\\pycharmprojects\\cyberattacksattention\\venv\\lib\\site-packages (from tensorflow-intel==2.11.0->tensorflow) (2.11.0)\n",
      "Requirement already satisfied: flatbuffers>=2.0 in c:\\users\\fer_u\\pycharmprojects\\cyberattacksattention\\venv\\lib\\site-packages (from tensorflow-intel==2.11.0->tensorflow) (22.12.6)\n",
      "Requirement already satisfied: wheel<1.0,>=0.23.0 in c:\\users\\fer_u\\pycharmprojects\\cyberattacksattention\\venv\\lib\\site-packages (from astunparse>=1.6.0->tensorflow-intel==2.11.0->tensorflow) (0.37.1)\n",
      "Requirement already satisfied: tensorboard-data-server<0.7.0,>=0.6.0 in c:\\users\\fer_u\\pycharmprojects\\cyberattacksattention\\venv\\lib\\site-packages (from tensorboard<2.12,>=2.11->tensorflow-intel==2.11.0->tensorflow) (0.6.1)\n",
      "Requirement already satisfied: werkzeug>=1.0.1 in c:\\users\\fer_u\\pycharmprojects\\cyberattacksattention\\venv\\lib\\site-packages (from tensorboard<2.12,>=2.11->tensorflow-intel==2.11.0->tensorflow) (2.2.2)\n",
      "Requirement already satisfied: google-auth-oauthlib<0.5,>=0.4.1 in c:\\users\\fer_u\\pycharmprojects\\cyberattacksattention\\venv\\lib\\site-packages (from tensorboard<2.12,>=2.11->tensorflow-intel==2.11.0->tensorflow) (0.4.6)\n",
      "Requirement already satisfied: requests<3,>=2.21.0 in c:\\users\\fer_u\\pycharmprojects\\cyberattacksattention\\venv\\lib\\site-packages (from tensorboard<2.12,>=2.11->tensorflow-intel==2.11.0->tensorflow) (2.28.1)\n",
      "Requirement already satisfied: tensorboard-plugin-wit>=1.6.0 in c:\\users\\fer_u\\pycharmprojects\\cyberattacksattention\\venv\\lib\\site-packages (from tensorboard<2.12,>=2.11->tensorflow-intel==2.11.0->tensorflow) (1.8.1)\n",
      "Requirement already satisfied: google-auth<3,>=1.6.3 in c:\\users\\fer_u\\pycharmprojects\\cyberattacksattention\\venv\\lib\\site-packages (from tensorboard<2.12,>=2.11->tensorflow-intel==2.11.0->tensorflow) (2.15.0)\n",
      "Requirement already satisfied: markdown>=2.6.8 in c:\\users\\fer_u\\pycharmprojects\\cyberattacksattention\\venv\\lib\\site-packages (from tensorboard<2.12,>=2.11->tensorflow-intel==2.11.0->tensorflow) (3.4.1)\n",
      "Requirement already satisfied: cachetools<6.0,>=2.0.0 in c:\\users\\fer_u\\pycharmprojects\\cyberattacksattention\\venv\\lib\\site-packages (from google-auth<3,>=1.6.3->tensorboard<2.12,>=2.11->tensorflow-intel==2.11.0->tensorflow) (5.2.0)\n",
      "Requirement already satisfied: pyasn1-modules>=0.2.1 in c:\\users\\fer_u\\pycharmprojects\\cyberattacksattention\\venv\\lib\\site-packages (from google-auth<3,>=1.6.3->tensorboard<2.12,>=2.11->tensorflow-intel==2.11.0->tensorflow) (0.2.8)\n",
      "Requirement already satisfied: rsa<5,>=3.1.4 in c:\\users\\fer_u\\pycharmprojects\\cyberattacksattention\\venv\\lib\\site-packages (from google-auth<3,>=1.6.3->tensorboard<2.12,>=2.11->tensorflow-intel==2.11.0->tensorflow) (4.9)\n",
      "Requirement already satisfied: requests-oauthlib>=0.7.0 in c:\\users\\fer_u\\pycharmprojects\\cyberattacksattention\\venv\\lib\\site-packages (from google-auth-oauthlib<0.5,>=0.4.1->tensorboard<2.12,>=2.11->tensorflow-intel==2.11.0->tensorflow) (1.3.1)\n",
      "Requirement already satisfied: importlib-metadata>=4.4 in c:\\users\\fer_u\\pycharmprojects\\cyberattacksattention\\venv\\lib\\site-packages (from markdown>=2.6.8->tensorboard<2.12,>=2.11->tensorflow-intel==2.11.0->tensorflow) (5.1.0)\n",
      "Requirement already satisfied: certifi>=2017.4.17 in c:\\users\\fer_u\\pycharmprojects\\cyberattacksattention\\venv\\lib\\site-packages (from requests<3,>=2.21.0->tensorboard<2.12,>=2.11->tensorflow-intel==2.11.0->tensorflow) (2022.12.7)\n",
      "Requirement already satisfied: charset-normalizer<3,>=2 in c:\\users\\fer_u\\pycharmprojects\\cyberattacksattention\\venv\\lib\\site-packages (from requests<3,>=2.21.0->tensorboard<2.12,>=2.11->tensorflow-intel==2.11.0->tensorflow) (2.1.1)\n",
      "Requirement already satisfied: idna<4,>=2.5 in c:\\users\\fer_u\\pycharmprojects\\cyberattacksattention\\venv\\lib\\site-packages (from requests<3,>=2.21.0->tensorboard<2.12,>=2.11->tensorflow-intel==2.11.0->tensorflow) (3.4)\n",
      "Requirement already satisfied: urllib3<1.27,>=1.21.1 in c:\\users\\fer_u\\pycharmprojects\\cyberattacksattention\\venv\\lib\\site-packages (from requests<3,>=2.21.0->tensorboard<2.12,>=2.11->tensorflow-intel==2.11.0->tensorflow) (1.26.13)\n",
      "Requirement already satisfied: MarkupSafe>=2.1.1 in c:\\users\\fer_u\\pycharmprojects\\cyberattacksattention\\venv\\lib\\site-packages (from werkzeug>=1.0.1->tensorboard<2.12,>=2.11->tensorflow-intel==2.11.0->tensorflow) (2.1.1)\n",
      "Requirement already satisfied: zipp>=0.5 in c:\\users\\fer_u\\pycharmprojects\\cyberattacksattention\\venv\\lib\\site-packages (from importlib-metadata>=4.4->markdown>=2.6.8->tensorboard<2.12,>=2.11->tensorflow-intel==2.11.0->tensorflow) (3.11.0)\n",
      "Requirement already satisfied: pyasn1<0.5.0,>=0.4.6 in c:\\users\\fer_u\\pycharmprojects\\cyberattacksattention\\venv\\lib\\site-packages (from pyasn1-modules>=0.2.1->google-auth<3,>=1.6.3->tensorboard<2.12,>=2.11->tensorflow-intel==2.11.0->tensorflow) (0.4.8)\n",
      "Requirement already satisfied: oauthlib>=3.0.0 in c:\\users\\fer_u\\pycharmprojects\\cyberattacksattention\\venv\\lib\\site-packages (from requests-oauthlib>=0.7.0->google-auth-oauthlib<0.5,>=0.4.1->tensorboard<2.12,>=2.11->tensorflow-intel==2.11.0->tensorflow) (3.2.2)\n"
     ]
    }
   ],
   "source": [
    "!pip install tensorflow"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Requirement already satisfied: pandas in c:\\users\\fer_u\\pycharmprojects\\cyberattacksattention\\venv\\lib\\site-packages (1.5.2)\n",
      "Requirement already satisfied: pytz>=2020.1 in c:\\users\\fer_u\\pycharmprojects\\cyberattacksattention\\venv\\lib\\site-packages (from pandas) (2022.6)\n",
      "Requirement already satisfied: numpy>=1.20.3 in c:\\users\\fer_u\\pycharmprojects\\cyberattacksattention\\venv\\lib\\site-packages (from pandas) (1.23.5)\n",
      "Requirement already satisfied: python-dateutil>=2.8.1 in c:\\users\\fer_u\\pycharmprojects\\cyberattacksattention\\venv\\lib\\site-packages (from pandas) (2.8.2)\n",
      "Requirement already satisfied: six>=1.5 in c:\\users\\fer_u\\pycharmprojects\\cyberattacksattention\\venv\\lib\\site-packages (from python-dateutil>=2.8.1->pandas) (1.16.0)\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "WARNING: You are using pip version 21.3.1; however, version 22.3.1 is available.\n",
      "You should consider upgrading via the 'C:\\Users\\Fer_U\\PycharmProjects\\CyberattacksAttention\\venv\\Scripts\\python.exe -m pip install --upgrade pip' command.\n"
     ]
    }
   ],
   "source": [
    "!pip install pandas"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Requirement already satisfied: neural_structured_learning in c:\\users\\fer_u\\pycharmprojects\\cyberattacksattention\\venv\\lib\\site-packages (1.4.0)\n",
      "Requirement already satisfied: six in c:\\users\\fer_u\\pycharmprojects\\cyberattacksattention\\venv\\lib\\site-packages (from neural_structured_learning) (1.16.0)\n",
      "Requirement already satisfied: scipy in c:\\users\\fer_u\\pycharmprojects\\cyberattacksattention\\venv\\lib\\site-packages (from neural_structured_learning) (1.9.3)\n",
      "Requirement already satisfied: attrs in c:\\users\\fer_u\\pycharmprojects\\cyberattacksattention\\venv\\lib\\site-packages (from neural_structured_learning) (22.1.0)\n",
      "Requirement already satisfied: absl-py in c:\\users\\fer_u\\pycharmprojects\\cyberattacksattention\\venv\\lib\\site-packages (from neural_structured_learning) (1.3.0)\n",
      "Requirement already satisfied: numpy<1.26.0,>=1.18.5 in c:\\users\\fer_u\\pycharmprojects\\cyberattacksattention\\venv\\lib\\site-packages (from scipy->neural_structured_learning) (1.23.5)\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "WARNING: You are using pip version 21.3.1; however, version 22.3.1 is available.\n",
      "You should consider upgrading via the 'C:\\Users\\Fer_U\\PycharmProjects\\CyberattacksAttention\\venv\\Scripts\\python.exe -m pip install --upgrade pip' command.\n"
     ]
    }
   ],
   "source": [
    "!pip install neural_structured_learning"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Requirement already satisfied: scikit_learn in c:\\users\\fer_u\\pycharmprojects\\cyberattacksattention\\venv\\lib\\site-packages (1.2.0)\n",
      "Requirement already satisfied: joblib>=1.1.1 in c:\\users\\fer_u\\pycharmprojects\\cyberattacksattention\\venv\\lib\\site-packages (from scikit_learn) (1.2.0)\n",
      "Requirement already satisfied: threadpoolctl>=2.0.0 in c:\\users\\fer_u\\pycharmprojects\\cyberattacksattention\\venv\\lib\\site-packages (from scikit_learn) (3.1.0)\n",
      "Requirement already satisfied: scipy>=1.3.2 in c:\\users\\fer_u\\pycharmprojects\\cyberattacksattention\\venv\\lib\\site-packages (from scikit_learn) (1.9.3)\n",
      "Requirement already satisfied: numpy>=1.17.3 in c:\\users\\fer_u\\pycharmprojects\\cyberattacksattention\\venv\\lib\\site-packages (from scikit_learn) (1.23.5)\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "WARNING: You are using pip version 21.3.1; however, version 22.3.1 is available.\n",
      "You should consider upgrading via the 'C:\\Users\\Fer_U\\PycharmProjects\\CyberattacksAttention\\venv\\Scripts\\python.exe -m pip install --upgrade pip' command.\n"
     ]
    }
   ],
   "source": [
    "!pip install scikit_learn"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "executionInfo": {
     "elapsed": 4460,
     "status": "ok",
     "timestamp": 1670604423667,
     "user": {
      "displayName": "Fernando José Rendón Segador",
      "userId": "09288482551460164544"
     },
     "user_tz": -60
    },
    "id": "bTL3Ufo0t487",
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "import tensorflow as tf\n",
    "import pandas as pd\n",
    "import neural_structured_learning as nsl\n",
    "import numpy as np\n",
    "from sklearn.preprocessing import LabelEncoder\n",
    "from sklearn import preprocessing\n",
    "from sklearn.model_selection import *"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "executionInfo": {
     "elapsed": 1214,
     "status": "ok",
     "timestamp": 1670604426852,
     "user": {
      "displayName": "Fernando José Rendón Segador",
      "userId": "09288482551460164544"
     },
     "user_tz": -60
    },
    "id": "xdB9GixktNz0",
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "df = pd.read_csv('CSE_CIC_IDS_2018/02-23-2018.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 300
    },
    "executionInfo": {
     "elapsed": 14,
     "status": "ok",
     "timestamp": 1670604426856,
     "user": {
      "displayName": "Fernando José Rendón Segador",
      "userId": "09288482551460164544"
     },
     "user_tz": -60
    },
    "id": "856UWFEmyUms",
    "outputId": "a5a2bcaf-4a37-454e-eb77-2ffe6b9b956f",
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": "   Dst Port  Protocol            Timestamp  Flow Duration  Tot Fwd Pkts  \\\n0        22         6  23/02/2018 08:18:29        1532698            11   \n1       500        17  23/02/2018 08:17:45      117573855             3   \n2       500        17  23/02/2018 08:17:45      117573848             3   \n3        22         6  23/02/2018 08:19:55        1745392            11   \n4       500        17  23/02/2018 08:18:17       89483474             6   \n\n   Tot Bwd Pkts  TotLen Fwd Pkts  TotLen Bwd Pkts  Fwd Pkt Len Max  \\\n0            11             1179             1969              648   \n1             0             1500                0              500   \n2             0             1500                0              500   \n3            11             1179             1969              648   \n4             0             3000                0              500   \n\n   Fwd Pkt Len Min  ...  Fwd Seg Size Min  Active Mean  Active Std  \\\n0                0  ...                32          0.0         0.0   \n1              500  ...                 8          0.0         0.0   \n2              500  ...                 8          0.0         0.0   \n3                0  ...                32          0.0         0.0   \n4              500  ...                 8    4000364.0         0.0   \n\n   Active Max  Active Min   Idle Mean      Idle Std  Idle Max  Idle Min  \\\n0           0           0         0.0  0.000000e+00         0         0   \n1           0           0  58786927.5  2.375324e+07  75583006  41990849   \n2           0           0  58786924.0  2.375325e+07  75583007  41990841   \n3           0           0         0.0  0.000000e+00         0         0   \n4     4000364     4000364  21370777.5  1.528092e+07  41989576   7200485   \n\n    Label  \n0  Benign  \n1  Benign  \n2  Benign  \n3  Benign  \n4  Benign  \n\n[5 rows x 80 columns]",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>Dst Port</th>\n      <th>Protocol</th>\n      <th>Timestamp</th>\n      <th>Flow Duration</th>\n      <th>Tot Fwd Pkts</th>\n      <th>Tot Bwd Pkts</th>\n      <th>TotLen Fwd Pkts</th>\n      <th>TotLen Bwd Pkts</th>\n      <th>Fwd Pkt Len Max</th>\n      <th>Fwd Pkt Len Min</th>\n      <th>...</th>\n      <th>Fwd Seg Size Min</th>\n      <th>Active Mean</th>\n      <th>Active Std</th>\n      <th>Active Max</th>\n      <th>Active Min</th>\n      <th>Idle Mean</th>\n      <th>Idle Std</th>\n      <th>Idle Max</th>\n      <th>Idle Min</th>\n      <th>Label</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>22</td>\n      <td>6</td>\n      <td>23/02/2018 08:18:29</td>\n      <td>1532698</td>\n      <td>11</td>\n      <td>11</td>\n      <td>1179</td>\n      <td>1969</td>\n      <td>648</td>\n      <td>0</td>\n      <td>...</td>\n      <td>32</td>\n      <td>0.0</td>\n      <td>0.0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0.0</td>\n      <td>0.000000e+00</td>\n      <td>0</td>\n      <td>0</td>\n      <td>Benign</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>500</td>\n      <td>17</td>\n      <td>23/02/2018 08:17:45</td>\n      <td>117573855</td>\n      <td>3</td>\n      <td>0</td>\n      <td>1500</td>\n      <td>0</td>\n      <td>500</td>\n      <td>500</td>\n      <td>...</td>\n      <td>8</td>\n      <td>0.0</td>\n      <td>0.0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>58786927.5</td>\n      <td>2.375324e+07</td>\n      <td>75583006</td>\n      <td>41990849</td>\n      <td>Benign</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>500</td>\n      <td>17</td>\n      <td>23/02/2018 08:17:45</td>\n      <td>117573848</td>\n      <td>3</td>\n      <td>0</td>\n      <td>1500</td>\n      <td>0</td>\n      <td>500</td>\n      <td>500</td>\n      <td>...</td>\n      <td>8</td>\n      <td>0.0</td>\n      <td>0.0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>58786924.0</td>\n      <td>2.375325e+07</td>\n      <td>75583007</td>\n      <td>41990841</td>\n      <td>Benign</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>22</td>\n      <td>6</td>\n      <td>23/02/2018 08:19:55</td>\n      <td>1745392</td>\n      <td>11</td>\n      <td>11</td>\n      <td>1179</td>\n      <td>1969</td>\n      <td>648</td>\n      <td>0</td>\n      <td>...</td>\n      <td>32</td>\n      <td>0.0</td>\n      <td>0.0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0.0</td>\n      <td>0.000000e+00</td>\n      <td>0</td>\n      <td>0</td>\n      <td>Benign</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>500</td>\n      <td>17</td>\n      <td>23/02/2018 08:18:17</td>\n      <td>89483474</td>\n      <td>6</td>\n      <td>0</td>\n      <td>3000</td>\n      <td>0</td>\n      <td>500</td>\n      <td>500</td>\n      <td>...</td>\n      <td>8</td>\n      <td>4000364.0</td>\n      <td>0.0</td>\n      <td>4000364</td>\n      <td>4000364</td>\n      <td>21370777.5</td>\n      <td>1.528092e+07</td>\n      <td>41989576</td>\n      <td>7200485</td>\n      <td>Benign</td>\n    </tr>\n  </tbody>\n</table>\n<p>5 rows × 80 columns</p>\n</div>"
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "executionInfo": {
     "elapsed": 9,
     "status": "ok",
     "timestamp": 1670604426856,
     "user": {
      "displayName": "Fernando José Rendón Segador",
      "userId": "09288482551460164544"
     },
     "user_tz": -60
    },
    "id": "mkez4dRDyZ4L",
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "label_encoder = LabelEncoder()\n",
    "df = df.replace([np.inf, -np.inf], np.nan)\n",
    "df = df.dropna()\n",
    "df = df.reset_index(drop=True)\n",
    "df = df.drop(['Timestamp'], axis=1)\n",
    "\n",
    "features = len(df.columns) - 1\n",
    "\n",
    "df['Label'] = label_encoder.fit_transform(df['Label'])\n",
    "classes = df['Label'].nunique()\n",
    "df = df.astype(float)\n",
    "df = df.astype(int)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 488
    },
    "executionInfo": {
     "elapsed": 10,
     "status": "ok",
     "timestamp": 1670604426857,
     "user": {
      "displayName": "Fernando José Rendón Segador",
      "userId": "09288482551460164544"
     },
     "user_tz": -60
    },
    "id": "6wz-53mHnm7p",
    "outputId": "fe64ae3c-8710-4fbe-fc93-ff39924faffd",
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": "         Dst Port  Protocol  Flow Duration  Tot Fwd Pkts  Tot Bwd Pkts  \\\n0              22         6        1532698            11            11   \n1             500        17      117573855             3             0   \n2             500        17      117573848             3             0   \n3              22         6        1745392            11            11   \n4             500        17       89483474             6             0   \n...           ...       ...            ...           ...           ...   \n1042862     54116         6       85992425             2             0   \n1042863     33914         6            132             2             0   \n1042864        53        17          79134             1             1   \n1042865      3389         6       10053785            11            12   \n1042866       445         6         566835             6             5   \n\n         TotLen Fwd Pkts  TotLen Bwd Pkts  Fwd Pkt Len Max  Fwd Pkt Len Min  \\\n0                   1179             1969              648                0   \n1                   1500                0              500              500   \n2                   1500                0              500              500   \n3                   1179             1969              648                0   \n4                   3000                0              500              500   \n...                  ...              ...              ...              ...   \n1042862                0                0                0                0   \n1042863                0                0                0                0   \n1042864               41               98               41               41   \n1042865             1321             1659              677                0   \n1042866              455              338              140                0   \n\n         Fwd Pkt Len Mean  ...  Fwd Seg Size Min  Active Mean  Active Std  \\\n0                     107  ...                32            0           0   \n1                     500  ...                 8            0           0   \n2                     500  ...                 8            0           0   \n3                     107  ...                32            0           0   \n4                     500  ...                 8      4000364           0   \n...                   ...  ...               ...          ...         ...   \n1042862                 0  ...                20            0           0   \n1042863                 0  ...                20            0           0   \n1042864                41  ...                 8            0           0   \n1042865               120  ...                20            0           0   \n1042866                75  ...                20            0           0   \n\n         Active Max  Active Min  Idle Mean  Idle Std  Idle Max  Idle Min  \\\n0                 0           0          0         0         0         0   \n1                 0           0   58786927  23753242  75583006  41990849   \n2                 0           0   58786924  23753248  75583007  41990841   \n3                 0           0          0         0         0         0   \n4           4000364     4000364   21370777  15280917  41989576   7200485   \n...             ...         ...        ...       ...       ...       ...   \n1042862           0           0   85992425         0  85992425  85992425   \n1042863           0           0          0         0         0         0   \n1042864           0           0          0         0         0         0   \n1042865           0           0          0         0         0         0   \n1042866           0           0          0         0         0         0   \n\n         Label  \n0            0  \n1            0  \n2            0  \n3            0  \n4            0  \n...        ...  \n1042862      0  \n1042863      0  \n1042864      0  \n1042865      0  \n1042866      0  \n\n[1042867 rows x 79 columns]",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>Dst Port</th>\n      <th>Protocol</th>\n      <th>Flow Duration</th>\n      <th>Tot Fwd Pkts</th>\n      <th>Tot Bwd Pkts</th>\n      <th>TotLen Fwd Pkts</th>\n      <th>TotLen Bwd Pkts</th>\n      <th>Fwd Pkt Len Max</th>\n      <th>Fwd Pkt Len Min</th>\n      <th>Fwd Pkt Len Mean</th>\n      <th>...</th>\n      <th>Fwd Seg Size Min</th>\n      <th>Active Mean</th>\n      <th>Active Std</th>\n      <th>Active Max</th>\n      <th>Active Min</th>\n      <th>Idle Mean</th>\n      <th>Idle Std</th>\n      <th>Idle Max</th>\n      <th>Idle Min</th>\n      <th>Label</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>22</td>\n      <td>6</td>\n      <td>1532698</td>\n      <td>11</td>\n      <td>11</td>\n      <td>1179</td>\n      <td>1969</td>\n      <td>648</td>\n      <td>0</td>\n      <td>107</td>\n      <td>...</td>\n      <td>32</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>500</td>\n      <td>17</td>\n      <td>117573855</td>\n      <td>3</td>\n      <td>0</td>\n      <td>1500</td>\n      <td>0</td>\n      <td>500</td>\n      <td>500</td>\n      <td>500</td>\n      <td>...</td>\n      <td>8</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>58786927</td>\n      <td>23753242</td>\n      <td>75583006</td>\n      <td>41990849</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>500</td>\n      <td>17</td>\n      <td>117573848</td>\n      <td>3</td>\n      <td>0</td>\n      <td>1500</td>\n      <td>0</td>\n      <td>500</td>\n      <td>500</td>\n      <td>500</td>\n      <td>...</td>\n      <td>8</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>58786924</td>\n      <td>23753248</td>\n      <td>75583007</td>\n      <td>41990841</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>22</td>\n      <td>6</td>\n      <td>1745392</td>\n      <td>11</td>\n      <td>11</td>\n      <td>1179</td>\n      <td>1969</td>\n      <td>648</td>\n      <td>0</td>\n      <td>107</td>\n      <td>...</td>\n      <td>32</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>500</td>\n      <td>17</td>\n      <td>89483474</td>\n      <td>6</td>\n      <td>0</td>\n      <td>3000</td>\n      <td>0</td>\n      <td>500</td>\n      <td>500</td>\n      <td>500</td>\n      <td>...</td>\n      <td>8</td>\n      <td>4000364</td>\n      <td>0</td>\n      <td>4000364</td>\n      <td>4000364</td>\n      <td>21370777</td>\n      <td>15280917</td>\n      <td>41989576</td>\n      <td>7200485</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>...</th>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n    </tr>\n    <tr>\n      <th>1042862</th>\n      <td>54116</td>\n      <td>6</td>\n      <td>85992425</td>\n      <td>2</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>...</td>\n      <td>20</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>85992425</td>\n      <td>0</td>\n      <td>85992425</td>\n      <td>85992425</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>1042863</th>\n      <td>33914</td>\n      <td>6</td>\n      <td>132</td>\n      <td>2</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>...</td>\n      <td>20</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>1042864</th>\n      <td>53</td>\n      <td>17</td>\n      <td>79134</td>\n      <td>1</td>\n      <td>1</td>\n      <td>41</td>\n      <td>98</td>\n      <td>41</td>\n      <td>41</td>\n      <td>41</td>\n      <td>...</td>\n      <td>8</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>1042865</th>\n      <td>3389</td>\n      <td>6</td>\n      <td>10053785</td>\n      <td>11</td>\n      <td>12</td>\n      <td>1321</td>\n      <td>1659</td>\n      <td>677</td>\n      <td>0</td>\n      <td>120</td>\n      <td>...</td>\n      <td>20</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>1042866</th>\n      <td>445</td>\n      <td>6</td>\n      <td>566835</td>\n      <td>6</td>\n      <td>5</td>\n      <td>455</td>\n      <td>338</td>\n      <td>140</td>\n      <td>0</td>\n      <td>75</td>\n      <td>...</td>\n      <td>20</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n    </tr>\n  </tbody>\n</table>\n<p>1042867 rows × 79 columns</p>\n</div>"
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "executionInfo": {
     "elapsed": 4,
     "status": "ok",
     "timestamp": 1670604427264,
     "user": {
      "displayName": "Fernando José Rendón Segador",
      "userId": "09288482551460164544"
     },
     "user_tz": -60
    },
    "id": "9s_HaYjkzuKk",
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "y = df.pop('Label')\n",
    "X = df\n",
    "\n",
    "normalizer_scaler = preprocessing.Normalizer()\n",
    "x_scaled = normalizer_scaler.fit_transform(X)\n",
    "X = pd.DataFrame(x_scaled)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "executionInfo": {
     "elapsed": 4,
     "status": "ok",
     "timestamp": 1670604427264,
     "user": {
      "displayName": "Fernando José Rendón Segador",
      "userId": "09288482551460164544"
     },
     "user_tz": -60
    },
    "id": "l-9LdOome2ck",
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.20, random_state=42)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "executionInfo": {
     "elapsed": 3,
     "status": "ok",
     "timestamp": 1670604427264,
     "user": {
      "displayName": "Fernando José Rendón Segador",
      "userId": "09288482551460164544"
     },
     "user_tz": -60
    },
    "id": "FC6lXk4Az3yB",
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "X_train = tf.convert_to_tensor(X_train)\n",
    "y_train = tf.convert_to_tensor(y_train)\n",
    "\n",
    "X_test = tf.convert_to_tensor(X_test)\n",
    "y_test = tf.convert_to_tensor(y_test)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "executionInfo": {
     "elapsed": 333,
     "status": "ok",
     "timestamp": 1670604427594,
     "user": {
      "displayName": "Fernando José Rendón Segador",
      "userId": "09288482551460164544"
     },
     "user_tz": -60
    },
    "id": "SP8ckOayytne",
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "input = tf.keras.layers.Input((features,), name='feature')\n",
    "\n",
    "n1 = tf.keras.layers.Dense(16)(input)\n",
    "n1 = tf.keras.layers.Dropout(0.25)(n1)\n",
    "n1 = tf.keras.layers.Dense(32)(n1)\n",
    "n1 = tf.keras.layers.Dropout(0.25)(n1)\n",
    "n1 = tf.keras.layers.Dense(64)(n1)\n",
    "n1 = tf.keras.layers.Dropout(0.25)(n1)\n",
    "n1 = tf.keras.layers.Dense(128)(n1)\n",
    "n1 = tf.keras.layers.Dropout(0.25)(n1)\n",
    "n1 = tf.keras.layers.Dense(256)(n1)\n",
    "\n",
    "n1 = tf.keras.layers.MultiHeadAttention(num_heads=int(256/8), key_dim=256, value_dim=256, attention_axes=1)(n1, n1, n1)\n",
    "\n",
    "n1 = tf.keras.layers.Dense(256)(n1)\n",
    "n1 = tf.keras.layers.Dropout(0.25)(n1)\n",
    "n1 = tf.keras.layers.Dense(128)(n1)\n",
    "n1 = tf.keras.layers.Dropout(0.25)(n1)\n",
    "n1 = tf.keras.layers.Dense(64)(n1)\n",
    "n1 = tf.keras.layers.Dropout(0.25)(n1)\n",
    "n1 = tf.keras.layers.Dense(32)(n1)\n",
    "n1 = tf.keras.layers.Dropout(0.25)(n1)\n",
    "n1 = tf.keras.layers.Dense(16)(n1)\n",
    "\n",
    "output = tf.keras.layers.Dense(classes, activation='softmax')(n1)\n",
    "\n",
    "model = tf.keras.Model(inputs=input, outputs=output)\n",
    "\n",
    "adv_config = nsl.configs.make_adv_reg_config(multiplier=0.2, adv_step_size=0.05)\n",
    "adv_model = nsl.keras.AdversarialRegularization(model, adv_config=adv_config)\n",
    "\n",
    "# Compile, train, and evaluate.\n",
    "adv_model.compile(optimizer='adam',\n",
    "                  loss='sparse_categorical_crossentropy',\n",
    "                  metrics=['accuracy'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "executionInfo": {
     "elapsed": 269,
     "status": "ok",
     "timestamp": 1670604427855,
     "user": {
      "displayName": "Fernando José Rendón Segador",
      "userId": "09288482551460164544"
     },
     "user_tz": -60
    },
    "id": "-EUxz4vRy7YP",
    "outputId": "1c8c1a81-6e6b-4129-f8a2-9d22f904cb87",
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Model: \"model\"\n",
      "__________________________________________________________________________________________________\n",
      " Layer (type)                   Output Shape         Param #     Connected to                     \n",
      "==================================================================================================\n",
      " feature (InputLayer)           [(None, 78)]         0           []                               \n",
      "                                                                                                  \n",
      " dense (Dense)                  (None, 16)           1264        ['feature[0][0]']                \n",
      "                                                                                                  \n",
      " dropout (Dropout)              (None, 16)           0           ['dense[0][0]']                  \n",
      "                                                                                                  \n",
      " dense_1 (Dense)                (None, 32)           544         ['dropout[0][0]']                \n",
      "                                                                                                  \n",
      " dropout_1 (Dropout)            (None, 32)           0           ['dense_1[0][0]']                \n",
      "                                                                                                  \n",
      " dense_2 (Dense)                (None, 64)           2112        ['dropout_1[0][0]']              \n",
      "                                                                                                  \n",
      " dropout_2 (Dropout)            (None, 64)           0           ['dense_2[0][0]']                \n",
      "                                                                                                  \n",
      " dense_3 (Dense)                (None, 128)          8320        ['dropout_2[0][0]']              \n",
      "                                                                                                  \n",
      " dropout_3 (Dropout)            (None, 128)          0           ['dense_3[0][0]']                \n",
      "                                                                                                  \n",
      " dense_4 (Dense)                (None, 256)          33024       ['dropout_3[0][0]']              \n",
      "                                                                                                  \n",
      " multi_head_attention (MultiHea  (None, 256)         8413440     ['dense_4[0][0]',                \n",
      " dAttention)                                                      'dense_4[0][0]',                \n",
      "                                                                  'dense_4[0][0]']                \n",
      "                                                                                                  \n",
      " dense_5 (Dense)                (None, 256)          65792       ['multi_head_attention[0][0]']   \n",
      "                                                                                                  \n",
      " dropout_4 (Dropout)            (None, 256)          0           ['dense_5[0][0]']                \n",
      "                                                                                                  \n",
      " dense_6 (Dense)                (None, 128)          32896       ['dropout_4[0][0]']              \n",
      "                                                                                                  \n",
      " dropout_5 (Dropout)            (None, 128)          0           ['dense_6[0][0]']                \n",
      "                                                                                                  \n",
      " dense_7 (Dense)                (None, 64)           8256        ['dropout_5[0][0]']              \n",
      "                                                                                                  \n",
      " dropout_6 (Dropout)            (None, 64)           0           ['dense_7[0][0]']                \n",
      "                                                                                                  \n",
      " dense_8 (Dense)                (None, 32)           2080        ['dropout_6[0][0]']              \n",
      "                                                                                                  \n",
      " dropout_7 (Dropout)            (None, 32)           0           ['dense_8[0][0]']                \n",
      "                                                                                                  \n",
      " dense_9 (Dense)                (None, 16)           528         ['dropout_7[0][0]']              \n",
      "                                                                                                  \n",
      " dense_10 (Dense)               (None, 4)            68          ['dense_9[0][0]']                \n",
      "                                                                                                  \n",
      "==================================================================================================\n",
      "Total params: 8,568,324\n",
      "Trainable params: 8,568,324\n",
      "Non-trainable params: 0\n",
      "__________________________________________________________________________________________________\n"
     ]
    }
   ],
   "source": [
    "model.summary()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 48
    },
    "executionInfo": {
     "elapsed": 447,
     "status": "ok",
     "timestamp": 1670604428298,
     "user": {
      "displayName": "Fernando José Rendón Segador",
      "userId": "09288482551460164544"
     },
     "user_tz": -60
    },
    "id": "844W7YPn82Gw",
    "outputId": "ea88bcec-2ee8-4229-e43f-6c1a767fdc89",
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "You must install pydot (`pip install pydot`) and install graphviz (see instructions at https://graphviz.gitlab.io/download/) for plot_model to work.\n"
     ]
    }
   ],
   "source": [
    "tf.keras.utils.plot_model(model, \n",
    "                          show_shapes=True,\n",
    "                          show_dtype=True,\n",
    "                          show_layer_names=True,\n",
    "                          rankdir='LR')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "id": "RjM9Xf2Ry-lq",
    "outputId": "3f4f80c6-a5ac-4e5e-8981-be5081cd7e3c",
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch 1/10\n",
      "WARNING:tensorflow:From C:\\Users\\Fer_U\\PycharmProjects\\CyberattacksAttention\\venv\\lib\\site-packages\\tensorflow\\python\\autograph\\pyct\\static_analysis\\liveness.py:83: Analyzer.lamba_check (from tensorflow.python.autograph.pyct.static_analysis.liveness) is deprecated and will be removed after 2023-09-23.\n",
      "Instructions for updating:\n",
      "Lambda fuctions will be no more assumed to be used in the statement where they are used, or at least in the same block. https://github.com/tensorflow/tensorflow/issues/56089\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "WARNING:absl:Cannot perturb non-Tensor input: dict_keys(['label'])\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1630/1630 [==============================] - 599s 365ms/step - loss: 0.0117 - sparse_categorical_crossentropy: 0.0096 - sparse_categorical_accuracy: 0.9988 - scaled_adversarial_loss: 0.0021 - val_loss: 0.0058 - val_sparse_categorical_crossentropy: 0.0047 - val_sparse_categorical_accuracy: 0.9995 - val_scaled_adversarial_loss: 0.0011\n",
      "Epoch 2/10\n",
      "1630/1630 [==============================] - 581s 357ms/step - loss: 0.0070 - sparse_categorical_crossentropy: 0.0057 - sparse_categorical_accuracy: 0.9995 - scaled_adversarial_loss: 0.0013 - val_loss: 0.0059 - val_sparse_categorical_crossentropy: 0.0048 - val_sparse_categorical_accuracy: 0.9995 - val_scaled_adversarial_loss: 0.0011\n",
      "Epoch 3/10\n",
      "1630/1630 [==============================] - 534s 328ms/step - loss: 0.0068 - sparse_categorical_crossentropy: 0.0055 - sparse_categorical_accuracy: 0.9995 - scaled_adversarial_loss: 0.0013 - val_loss: 0.0055 - val_sparse_categorical_crossentropy: 0.0043 - val_sparse_categorical_accuracy: 0.9995 - val_scaled_adversarial_loss: 0.0012\n",
      "Epoch 4/10\n",
      "1630/1630 [==============================] - 535s 328ms/step - loss: 0.0065 - sparse_categorical_crossentropy: 0.0052 - sparse_categorical_accuracy: 0.9995 - scaled_adversarial_loss: 0.0012 - val_loss: 0.0053 - val_sparse_categorical_crossentropy: 0.0043 - val_sparse_categorical_accuracy: 0.9995 - val_scaled_adversarial_loss: 0.0010\n",
      "Epoch 5/10\n",
      "1630/1630 [==============================] - 533s 327ms/step - loss: 0.0694 - sparse_categorical_crossentropy: 0.0571 - sparse_categorical_accuracy: 0.9988 - scaled_adversarial_loss: 0.0123 - val_loss: 0.0092 - val_sparse_categorical_crossentropy: 0.0075 - val_sparse_categorical_accuracy: 0.9995 - val_scaled_adversarial_loss: 0.0017\n",
      "Epoch 6/10\n",
      "1630/1630 [==============================] - 533s 327ms/step - loss: 0.0073 - sparse_categorical_crossentropy: 0.0059 - sparse_categorical_accuracy: 0.9994 - scaled_adversarial_loss: 0.0014 - val_loss: 0.0056 - val_sparse_categorical_crossentropy: 0.0046 - val_sparse_categorical_accuracy: 0.9995 - val_scaled_adversarial_loss: 0.0011\n",
      "Epoch 7/10\n",
      "1630/1630 [==============================] - 545s 335ms/step - loss: 0.0063 - sparse_categorical_crossentropy: 0.0051 - sparse_categorical_accuracy: 0.9995 - scaled_adversarial_loss: 0.0012 - val_loss: 0.0058 - val_sparse_categorical_crossentropy: 0.0047 - val_sparse_categorical_accuracy: 0.9995 - val_scaled_adversarial_loss: 0.0011\n",
      "Epoch 8/10\n",
      "1630/1630 [==============================] - 575s 353ms/step - loss: 0.0060 - sparse_categorical_crossentropy: 0.0049 - sparse_categorical_accuracy: 0.9995 - scaled_adversarial_loss: 0.0011 - val_loss: 0.0058 - val_sparse_categorical_crossentropy: 0.0047 - val_sparse_categorical_accuracy: 0.9995 - val_scaled_adversarial_loss: 0.0011\n",
      "Epoch 9/10\n",
      "1630/1630 [==============================] - 600s 368ms/step - loss: 0.0059 - sparse_categorical_crossentropy: 0.0048 - sparse_categorical_accuracy: 0.9995 - scaled_adversarial_loss: 0.0011 - val_loss: 0.0052 - val_sparse_categorical_crossentropy: 0.0041 - val_sparse_categorical_accuracy: 0.9995 - val_scaled_adversarial_loss: 0.0010\n",
      "Epoch 10/10\n",
      "1630/1630 [==============================] - 585s 359ms/step - loss: 0.0059 - sparse_categorical_crossentropy: 0.0048 - sparse_categorical_accuracy: 0.9995 - scaled_adversarial_loss: 0.0011 - val_loss: 0.0056 - val_sparse_categorical_crossentropy: 0.0045 - val_sparse_categorical_accuracy: 0.9995 - val_scaled_adversarial_loss: 0.0011\n"
     ]
    },
    {
     "data": {
      "text/plain": "<keras.callbacks.History at 0x196b23b5f40>"
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "adv_model.fit({'feature': X_train, 'label': y_train}, epochs=10, batch_size=512, validation_data={'feature': X_test, 'label': y_test})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "id": "Pmt7mlJoQ-Np",
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "208574/208574 [==============================] - 1390s 7ms/step - loss: 0.0056 - sparse_categorical_crossentropy: 0.0045 - sparse_categorical_accuracy: 0.9995 - scaled_adversarial_loss: 0.0011\n"
     ]
    },
    {
     "data": {
      "text/plain": "[0.005615883972495794,\n 0.004505567718297243,\n 0.9994677901268005,\n 0.0011104336008429527]"
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "adv_model.evaluate({'feature':X_test, 'label':y_test}, batch_size=1)"
   ]
  }
 ],
 "metadata": {
  "colab": {
   "provenance": [],
   "mount_file_id": "1l_2YpamsRqa2kvQbF6VcRh1L-ZVNw2LN",
   "authorship_tag": "ABX9TyOZ6tqQxYPy3g7WnP4d6Wrs"
  },
  "kernelspec": {
   "display_name": "Python 3",
   "name": "python3"
  },
  "language_info": {
   "name": "python"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}